package com.jdk.demo.thread.futureTask;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Demo {

	public static void main(String[] args) throws InterruptedException, ExecutionException {
		FutureTask<String> task = new FutureTask<>(() -> {
			System.out.println(System.currentTimeMillis() + ", thread go on...");
			Thread.sleep(1000);
			return "ok";
		});
		System.out.println(System.currentTimeMillis() + ", start...");
		new Thread(task).start();
		System.out.println(System.currentTimeMillis() + ", go on...");
		String result = task.get();
		System.out.println(System.currentTimeMillis() + ", " + result);
		String result2 = task.get();
		System.out.println(System.currentTimeMillis() + ", " + result2);
	}

}
